﻿
SET QUOTED_IDENTIFIER ON
GO

SET ANSI_NULLS ON
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_WA_ChangeDaySetting]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_WA_ChangeDaySetting];
GO
CREATE PROCEDURE [dbo].[sproc_WA_ChangeDaySetting]
    @day_xml xml
AS
BEGIN
SET NOCOUNT ON

/*
 * XML Format
 * <settings>
 *  <day value="" needDuty="" />
 *  ...
 * </settings>
 */
update
    d
set
    d.NeedDuty = R.x.value('@needDuty', 'bit')
from
    dbo.UDS_WorkAttendence_DaySetting d
    inner join @day_xml.nodes('/settings/day') R(x) on d.DayValue = R.x.value('@value', 'int');

END
GO